Begin Transaction;
Drop Table If Exists [mb_AlbumComment];
CREATE TABLE IF NOT EXISTS  [mb_AlbumComment] (
    [PKID] integer PRIMARY KEY AUTOINCREMENT NOT NULL,
    [AlbumID] integer NOT NULL,
    [CommentDate] timestamp DEFAULT CURRENT_TIMESTAMP,
    [Author] varchar(50),
    [Email] varchar(50),
    [Website] varchar(50),
    [Comment] varchar(200) NOT NULL,
    [Country] varchar(50),
    [IP] varchar(50),
    [IsApproved] boolean,
    CONSTRAINT [FK_mb_AlbumComment_AlbumID_mb_Albums_PKID] FOREIGN KEY ([AlbumID]) REFERENCES [mb_Albums] ([PKID])
);
Drop Table If Exists [mb_AlbumFile];
CREATE TABLE IF NOT EXISTS  [mb_AlbumFile] (
    [AlbumID] integer NOT NULL,
    [FileID] integer NOT NULL,
    CONSTRAINT [FK_mb_AlbumFile_AlbumID_mb_Albums_PKID] FOREIGN KEY ([AlbumID]) REFERENCES [mb_Albums] ([PKID]),
    CONSTRAINT [FK_mb_AlbumFile_FileID_mb_PortalFiles_PKID] FOREIGN KEY ([FileID]) REFERENCES [mb_PortalFiles] ([PKID])
);
Drop Table If Exists [mb_Albums];
CREATE TABLE IF NOT EXISTS  "mb_Albums"(
[PKID] integer PRIMARY KEY ON CONFLICT Abort AUTOINCREMENT UNIQUE ON CONFLICT Abort NOT NULL
,[Title] varchar(50) NOT NULL
,[Description] varchar(255) DEFAULT ''
,[Author] varchar(500) NOT NULL
,[Slug] varchar(50) DEFAULT ''
,[Hits] integer DEFAULT 0
,[IsPublic] boolean
,[IsPublished] boolean
,[IsCommentEnabled] boolean
,[DateCreated] timestamp DEFAULT CURRENT_TIMESTAMP
,[DateModified] timestamp DEFAULT CURRENT_TIMESTAMP
  
);
Drop Table If Exists [mb_AlbumTag];
CREATE TABLE IF NOT EXISTS  [mb_AlbumTag] (
    [AlbumID] integer NOT NULL,
    [Tag] varchar(50) NOT NULL,
    CONSTRAINT [FK_mb_AlbumTag_0] FOREIGN KEY ([AlbumID]) REFERENCES [mb_Albums] ([PKID])
);
Drop Table If Exists [mb_Categories];
CREATE TABLE IF NOT EXISTS  [mb_Categories] (
    [CategoryID] integer PRIMARY KEY AUTOINCREMENT NOT NULL,
    [CategoryName] varchar(50),
    [Description] varchar(100),
    [Slug] varchar(50) DEFAULT '',
    [Icon] varchar(50) DEFAULT '',
    [ParentID] integer NOT NULL,
    [DisplayOrder] integer DEFAULT 0,
    CONSTRAINT [FK_mb_Categories_ParentID_mb_Categories_CategoryID] FOREIGN KEY ([ParentID]) REFERENCES [mb_Categories] ([CategoryID])
);
Drop Table If Exists [mb_Communities];
CREATE TABLE IF NOT EXISTS  [mb_Communities] (
    [PKID] integer PRIMARY KEY AUTOINCREMENT NOT NULL,
    [Name] varchar(255) NOT NULL,
    [Description] text DEFAULT '',
    [Slug] varchar(50) DEFAULT '',
    [Icon] varchar(50) DEFAULT '',
    [ParentID] integer,
    CONSTRAINT [FK_mb_Communities_ParentID_mb_Communities_PKID] FOREIGN KEY ([ParentID]) REFERENCES [mb_Communities] ([PKID])
);
Drop Table If Exists [mb_CommunityTopic];
CREATE TABLE IF NOT EXISTS  [mb_CommunityTopic] (
    [CommunityID] integer NOT NULL,
    [TopicID] integer NOT NULL,
    CONSTRAINT [FK_mb_CommunityTopic_CommunityID_mb_Communities_PKID] FOREIGN KEY ([CommunityID]) REFERENCES [mb_Communities] ([PKID]),
    CONSTRAINT [FK_mb_CommunityTopic_TopicID_mb_Topics_TopicID] FOREIGN KEY ([TopicID]) REFERENCES [mb_Topics] ([TopicID])
);
Drop Table If Exists [mb_DataStoreSettings];
CREATE TABLE IF NOT EXISTS  "mb_DataStoreSettings" (
[ExtensionType] VARCHAR(50)  NOT NULL,
[ExtensionId] VARCHAR(100)  NOT NULL,
[Settings] TEXT  NULL
);
Drop Table If Exists [mb_Pages];
CREATE TABLE IF NOT EXISTS  "mb_Pages"(
[PageID] integer PRIMARY KEY ON CONFLICT Abort AUTOINCREMENT UNIQUE NOT NULL
,[Title] VARCHAR(255) NOT NULL
,[Description] TEXT
,[PageContent] TEXT
,[Keywords] VARCHAR(255)
,[DateCreated] TIMESTAMP DEFAULT CURRENT_TIMESTAMP
,[DateModified] TIMESTAMP DEFAULT CURRENT_TIMESTAMP
,[IsPublished] BOOLEAN
,[IsFrontPage] BOOLEAN
,[Parent] integer DEFAULT -1
,[ShowInList] BOOLEAN
,[Attachments] text DEFAULT ''
,[Slug] varchar(255) DEFAULT ''
  
);
Drop Table If Exists [mb_PingService];
CREATE TABLE IF NOT EXISTS  "mb_PingService" (
[PingServiceID] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,
[Link] VARCHAR(255)  NULL
);
Drop Table If Exists [mb_PortalFiles];
CREATE TABLE IF NOT EXISTS  "mb_PortalFiles"(
[PKID] integer PRIMARY KEY ON CONFLICT Abort AUTOINCREMENT UNIQUE NOT NULL
,[Name] varchar(50) DEFAULT ''
,[Url] varchar(50) NOT NULL
,[Hits] integer DEFAULT 0
,[Description] varchar(500) DEFAULT ''
  
);
Drop Table If Exists [mb_PostCategory];
CREATE TABLE IF NOT EXISTS  [mb_PostCategory] (
    [PostID] integer NOT NULL,
    [CategoryID] integer NOT NULL,
    CONSTRAINT [FK_mb_PostCategory_PostID_mb_Posts_PostID] FOREIGN KEY ([PostID]) REFERENCES [mb_Posts] ([PostID]),
    CONSTRAINT [FK_mb_PostCategory_CategoryID_mb_Categories_CategoryID] FOREIGN KEY ([CategoryID]) REFERENCES [mb_Categories] ([CategoryID])
);
Drop Table If Exists [mb_PostComment];
CREATE TABLE IF NOT EXISTS  [mb_PostComment] (
    [PKID] integer PRIMARY KEY AUTOINCREMENT NOT NULL,
    [PostID] integer NOT NULL,
    [CommentDate] timestamp DEFAULT CURRENT_TIMESTAMP,
    [Author] varchar(255),
    [Email] varchar(255),
    [Website] varchar(255),
    [Comment] text,
    [Country] varchar(255),
    [IP] varchar(50),
    [IsApproved] boolean,
    CONSTRAINT [FK_mb_PostComment_PostID_mb_Posts_PostID] FOREIGN KEY ([PostID]) REFERENCES [mb_Posts] ([PostID])
);
Drop Table If Exists [mb_PostNotify];
CREATE TABLE IF NOT EXISTS  [mb_PostNotify] (
    [PostID] integer NOT NULL,
    [NotifyAddress] varchar(255) NOT NULL,
    CONSTRAINT [FK_mb_PostNotify_0] FOREIGN KEY ([PostID]) REFERENCES [mb_Posts] ([PostID])
);
Drop Table If Exists [mb_Posts];
CREATE TABLE IF NOT EXISTS  "mb_Posts"(
[PostID] integer PRIMARY KEY ON CONFLICT Abort AUTOINCREMENT UNIQUE NOT NULL
,[Title] VARCHAR(255) NOT NULL
,[Description] TEXT
,[PostContent] TEXT
,[DateCreated] TIMESTAMP DEFAULT CURRENT_TIMESTAMP
,[DateModified] TIMESTAMP DEFAULT CURRENT_TIMESTAMP
,[Author] VARCHAR(50)
,[IsPublished] BOOLEAN
,[IsCommentEnabled] BOOLEAN
,[Raters] INTEGER DEFAULT '0'
,[Rating] INTEGER DEFAULT '0'
,[Slug] VARCHAR(255)
,[Attachments] text DEFAULT ''
  
);
Drop Table If Exists [mb_PostTag];
CREATE TABLE IF NOT EXISTS  [mb_PostTag] (
    [PostID] integer NOT NULL,
    [Tag] varchar(100) NOT NULL,
    CONSTRAINT [FK_mb_PostTag_PostID_mb_Posts_PostID] FOREIGN KEY ([PostID]) REFERENCES [mb_Posts] ([PostID])
);
Drop Table If Exists [mb_Profiles];
CREATE TABLE IF NOT EXISTS  "mb_Profiles" (
[ProfileID] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,
[UserName] VARCHAR(100)  NOT NULL,
[SettingName] VARCHAR(200)  NOT NULL,
[SettingValue] TEXT  NULL
);
Drop Table If Exists [mb_Rates];
CREATE TABLE IF NOT EXISTS  "mb_Rates"(
[PKID] integer PRIMARY KEY ON CONFLICT Abort AUTOINCREMENT UNIQUE NOT NULL
,[Title] varchar(255) NOT NULL
,[Memo] varchar(500) DEFAULT ''
,[Rating] float DEFAULT 1.0
,[Raters] text DEFAULT ''
,[Hits] integer DEFAULT 0
  
);
Drop Table If Exists [mb_Roles];
CREATE TABLE IF NOT EXISTS  "mb_Roles" (
[RoleID] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,
[Role] VARCHAR(100)  NOT NULL
);
Drop Table If Exists [mb_Settings];
CREATE TABLE IF NOT EXISTS  "mb_Settings" (
[SettingName] VARCHAR(50)  UNIQUE NOT NULL PRIMARY KEY,
[SettingValue] TEXT  NULL
);
Drop Table If Exists [mb_StopWords];
CREATE TABLE IF NOT EXISTS  "mb_StopWords" (
[StopWord] VARCHAR(50)  UNIQUE NOT NULL PRIMARY KEY
);
Drop Table If Exists [mb_TopicComment];
CREATE TABLE IF NOT EXISTS  [mb_TopicComment] (
    [PKID] integer PRIMARY KEY AUTOINCREMENT NOT NULL,
    [TopicID] integer NOT NULL,
    [CommentDate] timestamp DEFAULT CURRENT_TIMESTAMP,
    [Author] varchar(50),
    [Email] varchar(50) DEFAULT '',
    [Website] varchar(50) DEFAULT '',
    [Comment] text DEFAULT '',
    [Country] varchar(50) DEFAULT '',
    [IP] varchar(50) DEFAULT '',
    [IsApproved] boolean,
    CONSTRAINT [FK_mb_TopicComment_TopicID_mb_Topics_TopicID] FOREIGN KEY ([TopicID]) REFERENCES [mb_Topics] ([TopicID])
);
Drop Table If Exists [mb_Topics];
CREATE TABLE IF NOT EXISTS  "mb_Topics"(
[TopicID] integer PRIMARY KEY ON CONFLICT Abort AUTOINCREMENT UNIQUE NOT NULL ON CONFLICT Abort
,[Title] varchar(255) NOT NULL
,[Description] text DEFAULT ''
,[Content] text NOT NULL
,[DateCreated] timestamp DEFAULT CURRENT_TIMESTAMP
,[DateModified] timestamp DEFAULT CURRENT_TIMESTAMP
,[Author] varchar(500)
,[IsPublished] boolean
,[IsCommentEnabled] boolean
,[IsValuable] boolean
,[IsApproved] boolean
,[Icon] varchar(50) DEFAULT ''
  
);
Drop Table If Exists [mb_TopicTag];
CREATE TABLE IF NOT EXISTS  [mb_TopicTag] (
    [TopicID] integer NOT NULL,
    [Tag] varchar(25) NOT NULL,
    CONSTRAINT [FK_mb_TopicTag_TopicID_mb_Topics_TopicID] FOREIGN KEY ([TopicID]) REFERENCES [mb_Topics] ([TopicID])
);
Drop Table If Exists [mb_UserRoles];
CREATE TABLE IF NOT EXISTS  [mb_UserRoles] (
    [UserID] integer NOT NULL,
    [RoleID] integer NOT NULL,
    CONSTRAINT [FK_mb_UserRoles_UserID_mb_Users_UserID] FOREIGN KEY ([UserID]) REFERENCES [mb_Users] ([UserID]),
    CONSTRAINT [FK_mb_UserRoles_RoleID_mb_Roles_RoleID] FOREIGN KEY ([RoleID]) REFERENCES [mb_Roles] ([RoleID])
);
Drop Table If Exists [mb_Users];
CREATE TABLE IF NOT EXISTS  "mb_Users" (
[UserID] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,
[UserName] VARCHAR(100)  NOT NULL,
[Password] VARCHAR(255)  NULL,
[LastLoginTime] TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL,
[EmailAddress] VARCHAR(255)  NULL
);
Drop Table If Exists [mb_VoteItem];
CREATE TABLE IF NOT EXISTS  [mb_VoteItem] (
    [VoteID] integer NOT NULL,
    [RateID] integer NOT NULL,
    CONSTRAINT [FK_mb_VoteItem_VoteID_mb_Votes_PKID] FOREIGN KEY ([VoteID]) REFERENCES [mb_Votes] ([PKID]),
    CONSTRAINT [FK_mb_VoteItem_RateID_mb_Rates_PKID] FOREIGN KEY ([RateID]) REFERENCES [mb_Rates] ([PKID])
);
Drop Table If Exists [mb_Votes];
CREATE TABLE IF NOT EXISTS  "mb_Votes"(
[PKID] INTEger PRIMARY KEY ON CONFLICT Abort AUTOINCREMENT UNIQUE NOT NULL
,[Title] varchar(50) NOT NULL
,[Description] varchar(255) DEFAULT ''
,[Author] varchar(50)
,[DateCreated] timestamp DEFAULT CURRENT_TIMESTAMP
,[DateModified] timestamp DEFAULT CURRENT_TIMESTAMP
,[IsPublished] boolean
,[IsMultiple] boolean
  
);
Drop Index  If Exists [IDX_MB_DATASTORESETTINGS_];
CREATE INDEX IF NOT EXISTS  [IDX_MB_DATASTORESETTINGS_] ON "mb_DataStoreSettings"(
[ExtensionType]  ASC,
[ExtensionId]  ASC
);
Drop Index  If Exists [IDX_MB_PAGES_PAGEID];
CREATE INDEX IF NOT EXISTS  [IDX_MB_PAGES_PAGEID] ON "mb_Pages"(
[PageID]  ASC
);
Drop Index  If Exists [IDX_MB_PINGSERVICE_PINGSERVICEID];
CREATE UNIQUE INDEX IF NOT EXISTS  [IDX_MB_PINGSERVICE_PINGSERVICEID] ON "mb_PingService"(
[PingServiceID]  ASC
);
Drop Index  If Exists [IDX_MB_POSTCATEGORY_CATEGORYID];
CREATE INDEX IF NOT EXISTS  [IDX_MB_POSTCATEGORY_CATEGORYID] ON [mb_PostCategory] ([CategoryID]);
Drop Index  If Exists [IDX_MB_POSTCATEGORY_POSTID];
CREATE INDEX IF NOT EXISTS  [IDX_MB_POSTCATEGORY_POSTID] ON [mb_PostCategory] ([PostID]);
Drop Index  If Exists [IDX_MB_POSTCOMMENT_POSTID];
CREATE INDEX IF NOT EXISTS  [IDX_MB_POSTCOMMENT_POSTID] ON [mb_PostComment] ([PostID]);
Drop Index  If Exists [IDX_MB_POSTNOTIFY_POSTID];
CREATE INDEX IF NOT EXISTS  [IDX_MB_POSTNOTIFY_POSTID] ON [mb_PostNotify] ([PostID]);
Drop Index  If Exists [IDX_MB_POSTS_POSTID];
CREATE INDEX IF NOT EXISTS  [IDX_MB_POSTS_POSTID] ON "mb_Posts"(
[PostID]  ASC
);
Drop Index  If Exists [IDX_MB_POSTTAG_POSTID];
CREATE INDEX IF NOT EXISTS  [IDX_MB_POSTTAG_POSTID] ON [mb_PostTag] ([PostID]);
Drop Index  If Exists [IDX_MB_PROFILES_USERNAME];
CREATE INDEX IF NOT EXISTS  [IDX_MB_PROFILES_USERNAME] ON "mb_Profiles"(
[UserName]  ASC
);
Drop Index  If Exists [IDX_MB_ROLES_ROLE];
CREATE INDEX IF NOT EXISTS  [IDX_MB_ROLES_ROLE] ON "mb_Roles"(
[Role]  ASC
);
Drop Index  If Exists [IDX_MB_ROLES_ROLEID];
CREATE INDEX IF NOT EXISTS  [IDX_MB_ROLES_ROLEID] ON "mb_Roles"(
[RoleID]  ASC
);
Drop Index  If Exists [IDX_MB_SETTINGS_SETTINGNAME];
CREATE INDEX IF NOT EXISTS  [IDX_MB_SETTINGS_SETTINGNAME] ON "mb_Settings"(
[SettingName]  ASC
);
Drop Index  If Exists [IDX_MB_STOPWORDS_STOPWORD];
CREATE INDEX IF NOT EXISTS  [IDX_MB_STOPWORDS_STOPWORD] ON "mb_StopWords"(
[StopWord]  ASC
);
Drop Index  If Exists [IDX_MB_USERROLES_ROLEID];
CREATE INDEX IF NOT EXISTS  [IDX_MB_USERROLES_ROLEID] ON [mb_UserRoles] ([RoleID]);
Drop Index  If Exists [IDX_MB_USERROLES_USERID];
CREATE INDEX IF NOT EXISTS  [IDX_MB_USERROLES_USERID] ON [mb_UserRoles] ([UserID]);
Drop Index  If Exists [IDX_MB_USERS_USERID];
CREATE INDEX IF NOT EXISTS  [IDX_MB_USERS_USERID] ON "mb_Users"(
[UserID]  ASC
);
Drop Index  If Exists [IDX_MB_USERS_USERNAME];
CREATE INDEX IF NOT EXISTS  [IDX_MB_USERS_USERNAME] ON "mb_Users"(
[UserName]  ASC
);
Commit Transaction;
